package com._51cto.healthy.service;

import com._51cto.healthy.base.BaseMapper;
import com._51cto.healthy.content.P;
import com._51cto.healthy.mapper.CheckItemMapper;
import com._51cto.healthy.pojo.CheckItem;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/****
 * @Author:DancingHorse
 * @Description:TCheckitem业务层接口实现类
 * @Date 2022/4/14 0:16
 *****/
@DubboService
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper baseMapper;

    public BaseMapper<CheckItem> getDao(){
        return baseMapper;
    }


    @Override
    public P<CheckItem> queryPage(String query, Integer pageNum, Integer pageSize) {
        //开启分页插件
        PageHelper.startPage(pageNum,pageSize);
        //获取数据
        List<CheckItem> checkItems = baseMapper.queryByCodeOrName(query);
        //把获取到的数据存入pageInfo
        PageInfo<CheckItem> pageInfo = new PageInfo<>(checkItems);
        return new P()
               .setPageSize(pageInfo.getPageSize())
                .setPageNum(pageInfo.getPageNum())
                .setPages(pageInfo.getPages())
                .setTotal(pageInfo.getTotal())
                .setRows(pageInfo.getList());
    }

    @Override
    public void addList(List<CheckItem> item) {
        item.forEach(shs->{
            baseMapper.insert(shs);
        });
    }

    @Override
    public void deleteByPK(Integer pk) {
         baseMapper.deleteByPK(pk);
    }

    @Override
    public void insert(CheckItem checkItem) {
        baseMapper.insert(checkItem);
    }

    @Override
    public void update(CheckItem checkItem) {
        baseMapper.update(checkItem);
    }
}
